def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True

def closest_prime_number(words):
    numbers = {
        'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
        'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
    }

    try:

        num = int(''.join(str(numbers[word]) for word in words.split()))
        if 100 <= num <= 999:
            lower = num
            upper = num
            while True:
                lower -= 1
                upper += 1
                if is_prime(lower):
                    return lower
                if is_prime(upper):
                    return upper
        else:
            return "Wrong input"
    except (KeyError, ValueError):
        return "Wrong input"


words = input("Введите три слова: ")
result = closest_prime_number(words)
print(result)
